/*************************************************************************
	> File Name: 002.求结构体中各个字段的偏移量.c
	> Author: Maureen 
	> Mail: Maureen@qq.com 
	> Created Time: 四  8/26 18:32:26 2021
 ************************************************************************/

#include <stdio.h>

#define OFFSET(T, field) ({ \
    T temp; \
    (char *)&temp.field - (char *)&temp; \
})

struct Data {
    int a;
    double b;
    char c;
};

int main() {
    printf("%ld\n", OFFSET(struct Data, a)); //0
    printf("%ld\n", OFFSET(struct Data, b)); //8
    printf("%ld\n", OFFSET(struct Data, c)); //16
    return 0;
}
